<?php 
/***
 * 登录管理控制器
 */
class LoginController extends Controller{
	private $model;
	public function __init(){
		$this->model = K('Admin');
	}
	
	public function index(){
		if(IS_POST){
			if($_SESSION['code'] != strtoupper(Q('post.code'))) $this->error('验证不正确');
			if(!$userInfor = $this->model->login()) $this->error($this->model->error);
			//修改登录时间
			$data = array(
				'login' => time()
			);
			$this->model->where("aid={$userInfor['aid']}")->update($data);
			//建立用户名和用户id session
			$_SESSION['aid'] = $userInfor['aid'];
			$_SESSION['admin'] = $userInfor['username'];
			$this->success('登录成功',U('Admin/Index/index'));
		}
		//加载登录模板
		$this->display();
	}
	
	public function code(){
		$code = new Code();
		$code->show();
	}
	
	
	
	
}












 ?>